#ifndef _COMMOM_H
#define _COMMON_H
# include <stdio.h>
#include <stdlib.h>
#include <zephyr/kernel.h>
#include "motor.h"
#include "stepmotor.h"
#include "servo.h"
#include "sensor.h"

typedef struct __attribute__ ((__packed__)){
    uint8_t headL;
    uint8_t headH;
    uint8_t len;
    uint8_t cmd;
    Motor_Ctr motor_ctr;
    Stepmotor_Ctr stepmotor_ctr;
    Servo_Ctr servo_ctr;
    uint8_t crc16L;
    uint8_t crc16H;
}Host_Ctr_Cmd;


typedef struct __attribute__ ((__packed__)){
    uint8_t headL;
    uint8_t headH;
    uint8_t len;
    uint8_t cmd;
    Motor_Para motor_sta;
    Stepmotor_Sta stepmotor_sta;
    Servo_Sta servo_sta;
    Sensor_Sta sensor_sta;
    uint8_t crc16L;
    uint8_t crc16H;
}Dev_Sta_Data;


#define NANO_FRAME_HEAD_LOW      0x0D
#define NANO_FRAME_HEAD_HIGH     0x0A


#define NANO_FRAME_LEN          sizeof(Host_Ctr_Cmd)
#define NANO_FRAME_LEN_NOCRC    (sizeof(Host_Ctr_Cmd) -2)

#define DEV_FRAME_LEN          sizeof(Dev_Sta_Data)
#define DEV_FRAME_LEN_NOCRC    (sizeof(Dev_Sta_Data) -2)

#define     JOYSTICK_CMD        0x02U
#define     SHELL_OPEN          0x08U
#define     POWER_ON            0x011U
#define     POWER_OFF           0x012U

#define     DEV_STA_DATA        0x20U

void nano_uart_callback(const struct device *dev, void *user_data);
void nano_rx_dispense(void *p1, void *p2, void *p3);
void nano_tx_dispense(void *p1, void *p2, void *p3);
#endif
